package org.swxjava.assembler.avm1;

import java.util.Calendar;
import java.util.Date;

import org.swxjava.assembler.Constants;
import org.swxjava.assembler.ObjectCompiler;
import org.swxjava.util.Log;
import org.swxjava.util.LogFactory;

public class AsDate implements AsClass, ObjectCompiler {

	/** Logger */
	private static final Log LOG = LogFactory.getLog(AsDate.class);
	
	/** value */
	private long value = 0;

	public AsDate(long value) {
		this.value = value;
	}

	public AsDate(Calendar calendar) {
		value = calendar.getTime().getTime();
	}

	public AsDate(Date date) {
		value = date.getTime();
	}

	public int getByteSize() {
		return (toString().length() - 2) / 2;
	}

	public byte[] toBytecode() {
		// TODO Auto-generated method stub
		return null;
	}

	public String toString() {
		// arg value
		String bytecode = new AsLong(value).toString();
		// arg index
		bytecode += new AsInt(1).toString();
		// class name
		bytecode += Constants.DATA_TYPE_STRING + Constants.CLASS_DATE + Constants.NULL_TERMINATOR;
		// new
		bytecode += Constants.ACTION_NEW_OBJECT;
		if(LOG.isDebugEnabled()) {
			LOG.debug(value + " : " + bytecode.toUpperCase());
		}
		return bytecode.toUpperCase();
	}
}
